import 'package:bxultimate/app/router/router_name.dart';
import 'package:bxultimate/app/theme/app_theme.dart';
import 'package:bxultimate/data/request/home_request.dart';
import 'package:bxultimate/data/request/shop_request.dart';
import 'package:bxultimate/widgets/app/app_article_card.dart';
import 'package:bxultimate/widgets/app/app_shop_item_card.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';

class AroundTabItemView extends StatefulWidget {

  final String showType;

  const AroundTabItemView(
      {super.key, required this.showType});

  @override
  State<AroundTabItemView> createState() => _AroundTabItemViewState();
}

class _AroundTabItemViewState extends State<AroundTabItemView> {
  var listData = [];


  int page = 1;
  int size = 10;

  getData() async {
    listData.addAll( await ShopRequest.getShopList(page, size, widget.showType));
    setState(() {
    });
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getData();
  }

  @override
  Widget build(BuildContext context) {

    return EasyRefresh(
      header: TDRefreshHeader(),
      onRefresh: () async {
        page=1;
        listData = [];
        getData();
      },
      onLoad: () async {
        page++;
        getData();
      },
      child: ListView.builder(
        itemCount: listData.length,
        itemBuilder: (context, index) {
          return GestureDetector(
            onTap: () {
              Get.toNamed(RouterName.articleDetail,arguments: listData[index].id);
            },
            child: AppShopItemCard(
              shop: listData[index],
            ),
          );
        },
      ),
    );
  }
}
